import math
import sys
path = sys.argv[1]
maxuserno = int(sys.argv[2])

f = open(path, 'r')
ff = open(sys.argv[3], 'r')

key_words = {}
freqs = {}
total_words = 0

for line in ff:
	#print line
	list = line.split("	")
	freqs[list[0]] = int(list[1])
for line in f:
	word_freq = line.split(" ")

        if word_freq[0] == "###TOTAL###":
                total_words = int(word_freq[1])*1.0
		continue

	tf = (int(word_freq[1])*1.0) / total_words
	df = math.log(maxuserno/freqs[word_freq[0]], 2)
	tf_idf = tf*df
	
	key_words[word_freq[0]] = tf_idf
	
rev_keys = sorted(key_words, lambda x, y: cmp(key_words[y], key_words[x]))
for i in rev_keys:
    print i, key_words[i]	

